package edu.rit.drh4818.raytracing.tone;

import java.awt.Color;

/**
 * @author Darren Headrick
 *
 */
public class Ward extends ToneReproduction
{

	private double ldmax;
	
	public Ward( double lmax, double ldmax )
	{
		super( lmax );
		this.ldmax = ldmax;
	}
	
	public Color[][] transform(Color[][] original) 
	{
		double sf = 
			Math.pow( 
					(1.219 + Math.pow(ldmax/2F,.4) )/
					(1.219 + Math.pow(logAverage( original ),.4)), 2.5 );
		
		Color[][] rv = new Color[ original.length ][ original[0].length ];
		
		for( int x = 0; x < original.length; x++ )
		{
			for( int y = 0; y < original[x].length; y++ )
			{
				float red = (float)(calcLuminensce(original[x][y].getRed()) * sf / ldmax );
				float blue = (float)(calcLuminensce(original[x][y].getBlue()) * sf / ldmax);
				float green = (float)(calcLuminensce(original[x][y].getGreen()) * sf / ldmax );
				
				if( red > 1 ) red = 1;
				if( green > 1 ) green = 1;
				if( blue > 1 ) blue = 1;
				
				rv[x][y] = new Color( (float)(red), (float)(green), (float)(blue) );
			}
		}
		
		return rv;
	}


}
